var util = require("../../../../utils/util.js");
// pages/myCertification/myCertification.js
var app = getApp();
var rz_bg = app.globalData._network_path + 'rz_bg.png';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rz_bg: rz_bg,//背景
    usermagInfo:{},
    authInfo:{},
    user_id:'',
    auth_role:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if(util.isExitsVariable(options.user_id)){
      that.setData({
        user_id:options.user_id
      })
    }
    if(util.isExitsVariable(options.auth_role)){
      that.setData({
        auth_role:options.auth_role
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    if(that.data.auth_role==1){
      that.getUserInfo();
    }
    that.getAuthInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 //跳转到基本信息
 baseInfo(){
   wx.navigateTo({
     url: '../realname/realName/realName?user_id='+this.data.user_id+"&auth_role="+this.data.auth_role,
   })
 },
  //跳转到身份证信息
  uploadDocuments() {
    wx.navigateTo({
      url: '../realname/uploadDocuments/uploadDocuments?user_id=' + this.data.user_id+"&auth_role="+this.data.auth_role,
    })
  },
  //获取用户信息
  getUserInfo() {
    var that = this;
    app.ajax({
      url: "Engineer/User/getUserInfo",
      data: { user_id: that.data.user_id},
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            usermagInfo: res.data.data
          })
        } 
      }
    })
  },
  //获取用户认证信息
  getAuthInfo() {
    var that = this;
    var url = "Engineer/Realname/getAuthInfo";
    var data =  {user_id:that.data.user_id};
    var url_type = 0;
    if(that.data.auth_role!=1){
      url = "api/Realname/getAuthInfo";
      data =  {auth_role:that.data.auth_role};
      url_type = 2;
    }
    app.ajax({
      url: url,
      data: data,
      url_type:url_type,
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            authInfo: res.data.data,
          })
        }
      }
    })
  }
})